# -*- coding: utf-8 -*-
"""
Created on Thu Sep 12 16:41:33 2019

@author: Administrator
"""

# 1005 继续(3n+1)猜想
# 卡拉兹(Callatz)猜想：
# 对任何一个正整数 n，如果它是偶数，那么把它砍掉一半；如果它是奇数，那么把 (3n+1) 砍掉一半。这样一直反复砍下去，最后一定在某一步得到 n=1。

def test():
    # 循环遍历输入数据
    count = int(input())
    raw = input().split(' ')
    temp = []
    for index in range(count):
        temp.append(int(raw[index]))
    
    result = remove_callatz(temp)
    result.sort(reverse = True)
    result = [str(ele) for ele in result]
    # 最后序列从高到低输出
    print(" ".join(result))
    

# bug
#def remove_callatz(temp):
#    # 求出每一个数据的卡拉兹序列
#    i = 0
#    count = len(temp)
#    while count != i:
#        calz_result = callatz(temp[i])
#    # 遍历输入数据中
#        for j in range(len(calz_result)):
#            # 判断是否存在该数序列中
#            k = 0
#            while k != count:
#                if calz_result[j] == temp[k]:
#                    # 有就删除，没有就下一个
#                    temp.pop(k)
#                    count = count - 1
#                    continue
#                k = k + 1
#        i = i + 1
#    return temp
# 方案二：
# 先找出所有的不相同的callatz数，
# 从原数列中删除被覆盖的，剩下为所求
def remove_callatz(temp):
    all_callatz_number = set()
    count = len(temp)
    
    for i in range(count):
        result = callatz(temp[i])
        
        for q in range(len(result)):
            all_callatz_number.add(result[q])
    
    all_callatz_number = list(all_callatz_number)
    all_callatz_len = len(all_callatz_number)
    
    filted = []
    while count != 0:
        k = 0
        while k != all_callatz_len:
            if all_callatz_number[k] == temp[0]:
                temp.pop(0)
                count = count - 1
                break
            k = k + 1
        else:
            filted.append(temp.pop(0))
            count = count - 1
    return filted

#temp = [3, 5, 6, 7, 8, 11]
#print(remove_callatz(temp))


def callatz(number):
    result = []
    while number != 1:
        if number % 2 == 0:
            number = number // 2
            result.append(number)
        else:
            number = (3 * number + 1) // 2
            result.append(number)
    return result

#print(callatz(3))
    
test()
